#ifndef __USART_CONF_H__
#define __USART_CONF_H__

#include "gd32f4xx.h"
#include "systick.h"


#define USE_USART0	1
#define USE_USART1	0
#define USE_USART2	0
#define USE_UART3	0
#define USE_UART4	0
#define USE_USART5	1
#define USE_UART6	0
#define USE_UART7	0

#define USE_PRINT	0
//#define USE_PRINT	1
//#define USE_PRINT	2
//#define USE_PRINT	3
//#define USE_PRINT	4
//#define USE_PRINT	5
//#define USE_PRINT	6
//#define USE_PRINT	7


/**************** USART 0 *****************/
#if USE_USART0
#define USART0_ENABLE_SEND		1
#define USART0_ENABLE_RECV		1
#define USART0_RECV_LEN			1024
#define USART0_RECV_NVIC_IRQ	0, 0
#define USART0_RECV_CALLBACK	1
#define USART0_ENABLE_DMA_SEND	1
#define USART0_ENABLE_DMA_RECV	1

// TX GPIO config
// PIN:	|	PA9	|	PA15	|	PB6
// AF:	|	AF7	|	AF7		|	AF7
#define USART0_TX_RCU	RCU_GPIOA
#define USART0_TX_PORT	GPIOA
#define USART0_TX_PIN	GPIO_PIN_9
#define USART0_TX_AF	GPIO_AF_7

// RX GPIO config
// PIN:	| PA10	|  PB3	|  PB7
// AF:	| AF7	|  AF7	|  AF7
#define USART0_RX_RCU	RCU_GPIOA
#define USART0_RX_PORT	GPIOA
#define USART0_RX_PIN	GPIO_PIN_10
#define USART0_RX_AF	GPIO_AF_7

// 	USART0 
//		DMA		CHN		SUBPERI 
//	TX	1		7		4
//	RX	1		2		4
//	RX	1		5		4

// DMA TX config
#if USART0_ENABLE_DMA_SEND
#define USART0_DMA_TX			DMA1
#define USART0_DMA_TX_RCU		RCU_DMA1
#define USART0_DMA_TX_CHN		DMA_CH7
#define USART0_DMA_TX_SUBPERI	DMA_SUBPERI4
#endif

// DMA RX config
#if USART0_ENABLE_DMA_RECV
#define USART0_DMA_RX	 		DMA1
#define USART0_DMA_RX_RCU 		RCU_DMA1
#define USART0_DMA_RX_CHN 		DMA_CH2
#define USART0_DMA_RX_SUBPERI	DMA_SUBPERI4
#endif

// param config
#define USART0_PARAM_BAUDRATE		115200
#define USART0_PARAM_PARITY			USART_PM_NONE
#define USART0_PARAM_WORD_LEN		USART_WL_8BIT
#define USART0_PARAM_STOP_BIT		USART_STB_1BIT
#define USART0_PARAM_DATA_FIRST		USART_MSBF_LSB

#endif

/**************** USART 1 *****************/
#if USE_USART1
#define USART1_ENABLE_SEND		1
#define USART1_ENABLE_RECV		1
#define USART1_RECV_LEN				1024
#define USART1_RECV_NVIC_IRQ	0, 0
#define USART1_RECV_CALLBACK	1
#define USART1_ENABLE_DMA_SEND	1
#define USART1_ENABLE_DMA_RECV	1

// TX GPIO config
// PIN:	|	PA2	|	PD5
// AF:	|	AF7	|	AF7
#define USART1_TX_RCU		RCU_GPIOD
#define USART1_TX_PORT	GPIOD
#define USART1_TX_PIN		GPIO_PIN_5
#define USART1_TX_AF		GPIO_AF_7

// RX GPIO config
// PIN:	| PA3	|  PD6	
// AF:	| AF7	|  AF7	
#define USART1_RX_RCU		RCU_GPIOD
#define USART1_RX_PORT	GPIOD
#define USART1_RX_PIN		GPIO_PIN_6
#define USART1_RX_AF		GPIO_AF_7

// 	USART1 
//		DMA		CHN		SUBPERI 
//	TX	0		6		4
//	RX	0		5		4

// DMA TX config
#if USART1_ENABLE_DMA_SEND
#define USART1_DMA_TX					DMA0
#define USART1_DMA_TX_RCU			RCU_DMA0
#define USART1_DMA_TX_CHN			DMA_CH6
#define USART1_DMA_TX_SUBPERI	DMA_SUBPERI4
#endif

// DMA RX config
#if USART1_ENABLE_DMA_RECV
#define USART1_DMA_RX	 				DMA0
#define USART1_DMA_RX_RCU 		RCU_DMA0
#define USART1_DMA_RX_CHN 		DMA_CH5
#define USART1_DMA_RX_SUBPERI	DMA_SUBPERI4
#endif

// param config
#define USART1_PARAM_BAUDRATE			9600
#define USART1_PARAM_PARITY				USART_PM_NONE
#define USART1_PARAM_WORD_LEN			USART_WL_8BIT
#define USART1_PARAM_STOP_BIT			USART_STB_1BIT
#define USART1_PARAM_DATA_FIRST		USART_MSBF_LSB
#endif

/**************** USART 2 *****************/
#if USE_USART2
#define USART2_ENABLE_SEND		1
#define USART2_ENABLE_RECV		1
#define USART2_RECV_LEN				1024
#define USART2_RECV_NVIC_IRQ	0, 0
#define USART2_RECV_CALLBACK	1
#define USART2_ENABLE_DMA_SEND	1
#define USART2_ENABLE_DMA_RECV	0

// TX GPIO config
// PIN:	|	PB10	|	PC10	|	PD8
// AF:	|	AF7		|	AF7		|	AF7
#define USART2_TX_RCU			RCU_GPIOB
#define USART2_TX_PORT		GPIOB
#define USART2_TX_PIN			GPIO_PIN_10
#define USART2_TX_AF			GPIO_AF_7

// RX GPIO config
// PIN:	|	PB11	|	PC5		|	PD9
// AF:	|	AF7		|	AF7		|	AF7
#define USART2_RX_RCU			RCU_GPIOB
#define USART2_RX_PORT		GPIOB
#define USART2_RX_PIN			GPIO_PIN_11
#define USART2_RX_AF			GPIO_AF_7

// 	USART2 
//		DMA		CHN		SUBPERI 
//	TX	0		3		4
//	RX	0		1		4

// DMA TX config
#if USART2_ENABLE_DMA_SEND
#define USART2_DMA_TX					DMA0
#define USART2_DMA_TX_RCU			RCU_DMA0
#define USART2_DMA_TX_CHN			DMA_CH3
#define USART2_DMA_TX_SUBPERI	DMA_SUBPERI4
#endif

// DMA RX config
#if USART2_ENABLE_DMA_RECV
#define USART2_DMA_RX	 				DMA0
#define USART2_DMA_RX_RCU 		RCU_DMA0
#define USART2_DMA_RX_CHN 		DMA_CH1
#define USART2_DMA_RX_SUBPERI	DMA_SUBPERI4
#endif

// param config
#define USART2_PARAM_BAUDRATE		9600
#define USART2_PARAM_PARITY				USART_PM_NONE
#define USART2_PARAM_WORD_LEN			USART_WL_8BIT
#define USART2_PARAM_STOP_BIT			USART_STB_1BIT
#define USART2_PARAM_DATA_FIRST		USART_MSBF_LSB

#endif


/**************** UART 3 *****************/
#if USE_UART3
#define UART3_ENABLE_SEND		1
#define UART3_ENABLE_RECV		1
#define UART3_RECV_LEN			1024
#define UART3_RECV_NVIC_IRQ		2, 2
#define UART3_RECV_CALLBACK		1
#define UART3_ENABLE_DMA_SEND	1
#define UART3_ENABLE_DMA_RECV	1

// TX GPIO config
// PIN:	|	PA0	|	PC10
// AF:	|	AF8	|	AF8
#define UART3_TX_RCU	RCU_GPIOA
#define UART3_TX_PORT	GPIOA
#define UART3_TX_PIN	GPIO_PIN_2
#define UART3_TX_AF		GPIO_AF_8

// RX GPIO config
// PIN:	| PA1	|  PC11	
// AF:	| AF8	|  AF8	
#define UART3_RX_RCU	RCU_GPIOA
#define UART3_RX_PORT	GPIOA
#define UART3_RX_PIN	GPIO_PIN_3
#define UART3_RX_AF		GPIO_AF_8

// 	USART3 
//		DMA		CHN		SUBPERI 
//	TX	0		4		4
//	RX	0		2		4

// DMA TX config
#if UART3_ENABLE_DMA_SEND
#define UART3_DMA_TX			DMA0
#define UART3_DMA_TX_RCU		RCU_DMA0
#define UART3_DMA_TX_CHN		DMA_CH4
#define UART3_DMA_TX_SUBPERI	DMA_SUBPERI4
#endif

// DMA RX config
#if UART3_ENABLE_DMA_RECV
#define UART3_DMA_RX	 		DMA0
#define UART3_DMA_RX_RCU 		RCU_DMA0
#define UART3_DMA_RX_CHN 		DMA_CH2
#define UART3_DMA_RX_SUBPERI	DMA_SUBPERI4
#endif

// param config
#define UART3_PARAM_BAUDRATE		115200
#define UART3_PARAM_PARITY			USART_PM_NONE
#define UART3_PARAM_WORD_LEN		USART_WL_8BIT
#define UART3_PARAM_STOP_BIT		USART_STB_1BIT
#define UART3_PARAM_DATA_FIRST		USART_MSBF_LSB
#endif


/**************** UART 4 *****************/
#if USE_UART4
#define UART4_ENABLE_SEND		1
#define UART4_ENABLE_RECV		1
#define UART4_RECV_LEN			1024
#define UART4_RECV_NVIC_IRQ		2, 2
#define UART4_RECV_CALLBACK		1
#define UART4_ENABLE_DMA_SEND	1
#define UART4_ENABLE_DMA_RECV	1

// TX GPIO config
// PIN:	|	PC12
// AF:	|	AF8	
#define UART4_TX_RCU	RCU_GPIOC
#define UART4_TX_PORT	GPIOC
#define UART4_TX_PIN	GPIO_PIN_12
#define UART4_TX_AF		GPIO_AF_8

// RX GPIO config
// PIN:	| PD2	
// AF:	| AF8
#define UART4_RX_RCU	RCU_GPIOD
#define UART4_RX_PORT	GPIOD
#define UART4_RX_PIN	GPIO_PIN_2
#define UART4_RX_AF		GPIO_AF_8

// 	USART4 
//		DMA		CHN		SUBPERI 
//	TX	0		7		4
//	RX	0		0		4

// DMA TX config
#if UART4_ENABLE_DMA_SEND
#define UART4_DMA_TX			DMA0
#define UART4_DMA_TX_RCU		RCU_DMA0
#define UART4_DMA_TX_CHN		DMA_CH7
#define UART4_DMA_TX_SUBPERI	DMA_SUBPERI4
#endif

// DMA RX config
#if UART4_ENABLE_DMA_RECV
#define UART4_DMA_RX	 		DMA0
#define UART4_DMA_RX_RCU 		RCU_DMA0
#define UART4_DMA_RX_CHN 		DMA_CH0
#define UART4_DMA_RX_SUBPERI	DMA_SUBPERI4
#endif

// param config
#define UART4_PARAM_BAUDRATE		115200
#define UART4_PARAM_PARITY			USART_PM_NONE
#define UART4_PARAM_WORD_LEN		USART_WL_8BIT
#define UART4_PARAM_STOP_BIT		USART_STB_1BIT
#define UART4_PARAM_DATA_FIRST		USART_MSBF_LSB

#endif


/**************** USART 5 *****************/
#if USE_USART5
#define USART5_ENABLE_SEND		1
#define USART5_ENABLE_RECV		1
#define USART5_RECV_LEN				1024
#define USART5_RECV_NVIC_IRQ	0, 0
#define USART5_RECV_CALLBACK		1
#define USART5_ENABLE_DMA_SEND	1
#define USART5_ENABLE_DMA_RECV	1

// TX GPIO config 
// PIN:	|	PA11	|	PC6		|	PG14
// AF:	|	AF8		|	AF8		|	AF8
#define USART5_TX_RCU		RCU_GPIOG
#define USART5_TX_PORT	GPIOG
#define USART5_TX_PIN		GPIO_PIN_14
#define USART5_TX_AF		GPIO_AF_8

// RX GPIO config
// PIN:	|	PA12	|	PC7		|	PG9
// AF:	|	AF8		|	AF8		|	AF8
#define USART5_RX_RCU		RCU_GPIOG
#define USART5_RX_PORT	GPIOG
#define USART5_RX_PIN		GPIO_PIN_9
#define USART5_RX_AF		GPIO_AF_8

// 	USART2 
//		DMA		CHN		SUBPERI 
//	TX	1		6		5
//	TX	1		7		5
//	RX	1		1		5
//	RX	1		2		5

// DMA TX config
#if USART5_ENABLE_DMA_SEND
#define USART5_DMA_TX					DMA1
#define USART5_DMA_TX_RCU			RCU_DMA1
#define USART5_DMA_TX_CHN			DMA_CH6
#define USART5_DMA_TX_SUBPERI	DMA_SUBPERI5
#endif

// DMA RX config
#if USART5_ENABLE_DMA_RECV
#define USART5_DMA_RX	 				DMA1
#define USART5_DMA_RX_RCU 		RCU_DMA1
#define USART5_DMA_RX_CHN 		DMA_CH1
#define USART5_DMA_RX_SUBPERI	DMA_SUBPERI5
#endif

// param config
#define USART5_PARAM_BAUDRATE			9600
#define USART5_PARAM_PARITY				USART_PM_NONE
#define USART5_PARAM_WORD_LEN			USART_WL_8BIT
#define USART5_PARAM_STOP_BIT			USART_STB_1BIT
#define USART5_PARAM_DATA_FIRST		USART_MSBF_LSB

#endif


/**************** UART 6 *****************/
#if USE_UART6
#define UART6_ENABLE_SEND		1
#define UART6_ENABLE_RECV		1
#define UART6_RECV_LEN			1024
#define UART6_RECV_NVIC_IRQ		2, 2
#define UART6_RECV_CALLBACK		1
#define UART6_ENABLE_DMA_SEND	1
#define UART6_ENABLE_DMA_RECV	1

// TX GPIO config
// PIN:	|	PE8	| PF7
// AF:	|	AF8	| AF8
#define UART6_TX_RCU	RCU_GPIOE
#define UART6_TX_PORT	GPIOE
#define UART6_TX_PIN	GPIO_PIN_8
#define UART6_TX_AF		GPIO_AF_8

// RX GPIO config
// PIN:	| PE7	| PE8	
// AF:	| AF8	| AF8
#define UART6_RX_RCU	RCU_GPIOE
#define UART6_RX_PORT	GPIOE
#define UART6_RX_PIN	GPIO_PIN_7
#define UART6_RX_AF		GPIO_AF_8

// 	USART6 
//		DMA		CHN		SUBPERI 
//	TX	0		1		5
//	RX	0		3		5

// DMA TX config
#if UART6_ENABLE_DMA_SEND
#define UART6_DMA_TX			DMA0
#define UART6_DMA_TX_RCU		RCU_DMA0
#define UART6_DMA_TX_CHN		DMA_CH1
#define UART6_DMA_TX_SUBPERI	DMA_SUBPERI5
#endif

// DMA RX config
#if UART6_ENABLE_DMA_RECV
#define UART6_DMA_RX	 		DMA0
#define UART6_DMA_RX_RCU 		RCU_DMA0
#define UART6_DMA_RX_CHN 		DMA_CH3
#define UART6_DMA_RX_SUBPERI	DMA_SUBPERI5
#endif

// param config
#define UART6_PARAM_BAUDRATE		115200
#define UART6_PARAM_PARITY			USART_PM_NONE
#define UART6_PARAM_WORD_LEN		USART_WL_8BIT
#define UART6_PARAM_STOP_BIT		USART_STB_1BIT
#define UART6_PARAM_DATA_FIRST		USART_MSBF_LSB

#endif


/**************** USART 7 *****************/
#if USE_UART7
#define UART7_ENABLE_SEND		1
#define UART7_ENABLE_RECV		1
#define UART7_RECV_LEN			1024
#define UART7_RECV_NVIC_IRQ		2, 2
#define UART7_RECV_CALLBACK		1
#define UART7_ENABLE_DMA_SEND	1
#define UART7_ENABLE_DMA_RECV	1

// TX GPIO config
// PIN:	|	PE1
// AF:	|	AF8
#define UART7_TX_RCU	RCU_GPIOE
#define UART7_TX_PORT	GPIOE
#define UART7_TX_PIN	GPIO_PIN_1
#define UART7_TX_AF		GPIO_AF_8

// RX GPIO config
// PIN:	| PE0
// AF:	| AF8
#define UART7_RX_RCU	RCU_GPIOE
#define UART7_RX_PORT	GPIOE
#define UART7_RX_PIN	GPIO_PIN_0
#define UART7_RX_AF		GPIO_AF_8

// 	USART7 
//		DMA		CHN		SUBPERI 
//	TX	0		0		5
//	RX	0		6		5

// DMA TX config
#if UART7_ENABLE_DMA_SEND
#define UART7_DMA_TX			DMA0
#define UART7_DMA_TX_RCU		RCU_DMA0
#define UART7_DMA_TX_CHN		DMA_CH0
#define UART7_DMA_TX_SUBPERI	DMA_SUBPERI5
#endif

// DMA RX config
#if UART7_ENABLE_DMA_RECV
#define UART7_DMA_RX	 		DMA0
#define UART7_DMA_RX_RCU 		RCU_DMA0
#define UART7_DMA_RX_CHN 		DMA_CH6
#define UART7_DMA_RX_SUBPERI	DMA_SUBPERI5
#endif

// param config
#define UART7_PARAM_BAUDRATE		115200
#define UART7_PARAM_PARITY			USART_PM_NONE
#define UART7_PARAM_WORD_LEN		USART_WL_8BIT
#define UART7_PARAM_STOP_BIT		USART_STB_1BIT
#define UART7_PARAM_DATA_FIRST		USART_MSBF_LSB

#endif


#endif